package com.authstr.controller;

import java.util.Enumeration;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;


@Controller
public class PageController  {
    private String skin="default/simple";
	@RequestMapping("/index")
    public ModelAndView index(ModelAndView model) {
        model.setViewName("/index");
        return model;
    }

    @RequestMapping("/index_test")
    public ModelAndView index_test(ModelAndView model) {
        model.setViewName("/index_test");
        return model;
    }
    @RequestMapping("p/view/{pkg}/{page}")
    public ModelAndView page_view(ModelAndView model,@PathVariable("pkg") String pkg,
    		@PathVariable("page") String page,HttpServletRequest rqRequest) {
    	//将所有参数放到modelAndView
        if (rqRequest.getParameterNames().hasMoreElements()) {
            Enumeration<String> pm = rqRequest.getParameterNames();
            while (pm.hasMoreElements()) {
                String key = pm.nextElement();
                if (key.equals(pkg) || key.equals(page)) {
                    continue;
                }
                model.addObject(key, rqRequest.getParameter(key));
            }
        }
        model.setViewName("/" + pkg + "/" + page);
        return model;
    }

}
